package com.itgan.userbackendmanagement.common.respondResult;


import com.itgan.userbackendmanagement.common.enumeration.ErrorCodeEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * 全局通用返回
 *
 * @param <T>
 *
 * @author agan
 */

@Data
public class  Result<T> implements Serializable{


    private int code; //编码：1成功，0和其它数字为失败
    private String massage; //错误信息
    private T data; //数据
    private String description;



    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        result.code = 1;
        result.data = null;
        result.massage = "";
        result.description = "";
        return result;
    }

    public static <T> Result<T> success(T Object) {
        Result<T> result = new Result<T>();
        result.data = Object;
        result.code = 1;
        result.massage = "";
        result.description = "";
        return result;
    }

    public static <T> Result<T> error(String massage) {
        Result<T> result = new Result<T>();
        result.massage = massage;
        result.code = 0;
        result.data = null;
        result.description = "";
        return result;
    }
    public static <T> Result<T> error(int code,String massage,String description) {
        Result<T> result = new Result<T>();
        result.data = null;
        result.massage = massage;
        result.code = code;
        result.description = description;
        return result;
    }
    public static <T> Result<T> error(ErrorCodeEnum errorCodeEnum,String massage,String description) {
        Result<T> result = new Result<T>();
        result.data = null;
        result.massage = massage;
        result.code = errorCodeEnum.getCode();
        result.description = description;
        return result;
    }




}
